home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 109_01.zip / LISTF.C < prev    next >
Text File  |  1993-06-26  |  2KB  |  123 lines

  1. /*
  2.  
  3. This utility copies a record from a named file to the printer. Records
  4. may be selected by random within the file. References outside the bounds
  5. of the file result in the read buffer contents remaining unchanged and
  6. thus printing identically again.
  7.  
  8. The print format is:
  9.     top line ASCII
  10.     second line high order hex nibble
  11.     third line   low order hex nibble
  12.  
  13. The record is printed in two segments to accomodate 8 inch paper. 
  14. arguments are suppled during execution.
  15. */
  16. #include "bdscio.h"
  17. #define input 0
  18.  
  19. main()
  20.  
  21. {
  22. char buffer[324];
  23. char fname[20];
  24. int fd;
  25.  
  26. for (;;){
  27.     printf("FILE DESCRIPTOR--");
  28.     if (scanf("%s\n",fname)==0) break;
  29.     fd=open(fname,input);
  30.     do_sector(fd,buffer);
  31.     close(fd);
  32.     }
  33. }
  34.  
  35. do_sector(fdes,buf)
  36.  
  37. int fdes;
  38. char buf[];
  39. {
  40. int i;
  41. int sect;
  42. char instr[135];
  43.  
  44. for(;;){
  45.     printf("RECORD--");
  46.     if (scanf("%d\n",§)==0) break;
  47.     seek(fdes,sect,0);
  48.     read(fdes,buf,1);
  49.     trxln(buf,sect);
  50.     fprintf(2,"\n");
  51.     }
  52. }
  53. /*
  54.             trxln
  55.  
  56. This routine translates the line in buf, printing it as ascii 
  57. when reasonable and always printing a hex version. The line is
  58. printed in two segments, one containing a record number and
  59. 50 elements, the second containing the balance.
  60. */
  61.  
  62. trxln(buf,sect)
  63.  
  64. char *buf;
  65. {
  66. int loval;
  67. int hival;
  68. int i,j;
  69.  
  70. for(i=0;i<3;i++){
  71.     for(j=0;j<128;j++){
  72.         if (!(i+j)) fprintf(2,"RECORD %d\n",sect);
  73.         switch(i){
  74.             case 0:
  75.                 if((buf[j]<127)&&(buf[j]>31))
  76.                    putc(buf[j],2);
  77.                 else putc('.',2);
  78.                 break;
  79.             case 2:
  80.                 loval=buf[j];
  81.                 loval=loval & 0x0f;
  82.                 loval=asciihex(loval);
  83.                 putc(loval,2);
  84.                 break;
  85.             case 1:
  86.                 hival=buf[j];
  87.                 hival=hival & 0xf0;
  88.                 hival=hival>>4;
  89.                 hival=asciihex(hival);
  90.                 putc(hival,2);
  91.                 break;
  92.             }
  93.         if(j==60){
  94.             fprintf(2,"\n");
  95.             if(i<2){i++;j=-1;}
  96.             else i=0;
  97.             }
  98.         if(j==127){
  99.             fprintf(2,"\n");
  100.             if (i<2){
  101.                 j=60;
  102.                 i++;
  103.                 }
  104.             }
  105.         }
  106.     }
  107. }
  108. /*
  109.             asciihex
  110.  
  111. This function accepts a value between 0 and 15 and returns
  112. the ascii equivalent
  113. */
  114.  
  115. char asciihex(inval)
  116.  
  117. int inval;
  118. {
  119. if(inval<10) inval+=0x30;
  120. else inval+=0x37;
  121. return inval;
  122. }
  123.